package cn.ekuma.android.ui.filter;

import cn.ekuma.data.ui.android.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class RefSelectFilter extends LinearLayout{
	public interface RefSelectedListener {
		void refSelected(RefSelectFilter filter,int requestCode);
	}

	protected Button btnSelect;
	protected TextView txtName;
	
    private int requestCode;
    
    private RefSelectedListener l;
	
	public RefSelectFilter(Context context,int requestCode,String txtName1) {
		super(context);
		init(context);
		this.requestCode=requestCode;
		txtName.setText(txtName1);
	}
	
	public RefSelectFilter(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	
    private void init(final Context context) {
    	View mainView = LayoutInflater.from(context).inflate( R.layout.ref_select_filter, this); 
    	btnSelect=(Button) mainView.findViewById(R.id.btnrefSelect);
    	btnSelect.setOnClickListener(new OnClickListener(){
			
			public void onClick(View v) {
				fireStartActivateForResert();
			}  		
    	});
    	txtName=(TextView) mainView.findViewById(R.id.txtrefselectName);
    	
     }

	public void fireStartActivateForResert(){
		if(l!=null)
			l.refSelected(this, requestCode);
	}
	
	public void setSelectedBeanText(String text){
		btnSelect.setText(text);
	}


	public void setRefSelectedListener(RefSelectedListener l) {
		this.l = l;
	}
	
	public void removeRefSelectedListener(){
		this.l=null;
	}
	
}
